package com.ddmmo.exhibition.localBOSS.project.controller;

import com.ddmmo.exhibition.common.annotation.WebLog;
import com.ddmmo.exhibition.common.entity.Result;
import com.ddmmo.exhibition.localBOSS.project.entity.po.TbProjectClassifyPO;
import com.ddmmo.exhibition.localBOSS.project.entity.vo.ProjectClassifyListVO;
import com.ddmmo.exhibition.localBOSS.project.service.ProjectClassifyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 项目分类-所属分类 - Controller
 * </p>
 *
 * @author JiangYiji
 * @since 2024/10/30
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/projectClassify")
@Api(tags = "后台管理-所属分类Controller")
public class ProjectClassifyController {

    @Autowired
    private ProjectClassifyService projectClassifyService;

    @WebLog
    @GetMapping("/selectAllProjectClassify")
    @ApiOperation(value = "查询所有项目分类-树结构")
    public Result<List<ProjectClassifyListVO>> selectAllProjectClassify() {
        List<ProjectClassifyListVO> classifyList = projectClassifyService.selectAllProjectClassify();
        return Result.success(classifyList);
    }

    @WebLog
    @GetMapping("/selectProjectClassifyById/{id}")
    @ApiOperation(value = "根据ID查询分类")
    public Result<TbProjectClassifyPO> selectProjectClassifyById(@PathVariable String id) {
        TbProjectClassifyPO projectClassify = projectClassifyService.selectProjectClassifyById(id);
        return Result.success(projectClassify);
    }

    @WebLog
    @PostMapping ("/selectProjectClassifyByNameOrId")
    @ApiOperation(value = "根据名字或者ID查询子类（树形）")
    public Result<List<ProjectClassifyListVO>> selectProjectClassifyByNameOrId(@RequestParam String name,@RequestParam String id) {
        List<ProjectClassifyListVO> projectClassify = projectClassifyService.selectProjectClassifyByNameOrId(name,id);
        return Result.success(projectClassify);
    }

    @WebLog
    @PostMapping("/addProjectClassify")
    @ApiOperation(value = "添加新分类")
    public Result addProjectClassify(@RequestBody List<TbProjectClassifyPO> projectClassifys) {
        return projectClassifyService.addProjectClassify(projectClassifys);
    }

    @WebLog
    @PostMapping("/updateProjectClassify")
    @ApiOperation(value = "根据ID更新分类")
    public Result updateProjectClassify(@RequestBody TbProjectClassifyPO projectClassify) {
        return projectClassifyService.updateProjectClassify(projectClassify);
    }

    @WebLog
    @GetMapping("/deleteProjectClassifyById/{id}")
    @ApiOperation(value = "根据ID删除分类")
    public Result deleteProjectClassifyById(@PathVariable String id) {
        return projectClassifyService.deleteProjectClassifyById(id);
    }

    @WebLog
    @GetMapping("/selectAllParentClassify")
    @ApiOperation(value = "查询所有父类（不包括最小子类）")
    public Result<List<TbProjectClassifyPO>> selectAllParentClassify() {
        List<TbProjectClassifyPO> parentClassifyList = projectClassifyService.selectAllParentClassify();
        return Result.success(parentClassifyList);
    }

    @WebLog
    @GetMapping("/selectAllChildClassify")
    @ApiOperation(value = "查询所有子类（不包括最大父类）")
    public Result<List<TbProjectClassifyPO>> selectAllChildClassify() {
        List<TbProjectClassifyPO> childClassifyList = projectClassifyService.selectAllChildClassify();
        return Result.success(childClassifyList);
    }

    @WebLog
    @GetMapping("/selectChildByParentId/{id}")
    @ApiOperation(value = "查询所有父类的子类")
    public Result<List<TbProjectClassifyPO>> selectChildByParentId(@PathVariable String id) {
        List<TbProjectClassifyPO> childClassifyList = projectClassifyService.selectChildByParentId(id);
        return Result.success(childClassifyList);
    }

}
